package com.eascs.archive.dao;

import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;
import com.eascs.admin.common.dao.BaseO2oDao;
import com.eascs.admin.o2o.internal.entity.PubDditem;
import com.eascs.archive.entity.ArchiveLinkEntity;
import com.eascs.deploy.entity.O2oDeployFile;

@Repository
public class ArchiveDao extends BaseO2oDao{
	
	public List<ArchiveLinkEntity> getArchiveLinkList(String bankTypeId, String formTypeId){
		if (StringUtils.isBlank(bankTypeId) || StringUtils.isBlank(formTypeId)) {
			return null;
		}
		String sql="select * from o2o_archive_link where bank_type_id=? and form_type_id=?";
		return o2oJdbcSession.findEntitys(sql, ArchiveLinkEntity.class, new Object[]{bankTypeId,formTypeId});
	}
	
	public PubDditem getFieldById(String itemNo){
		if (StringUtils.isBlank(itemNo)) {
			return null;
		}
		String sql="select * from pub_dditem_o2o where item_no=?";
		return o2oJdbcSession.findEntity(sql, PubDditem.class, new Object[]{itemNo});
	}
	
	
	public PubDditem getBankByCode(String itemCode){
		if (StringUtils.isBlank(itemCode)) {
			return null;
		}
		String sql="select * from pub_dditem_o2o where item_code=? and dd_no='40001'";
		return o2oJdbcSession.findEntity(sql, PubDditem.class, new Object[]{itemCode});
	}
	
	public  List<PubDditem> findAllFiles() {
		String sql = "SELECT * FROM pub_dditem_o2o WHERE dd_no='40002'";
		return this.findEntitys(sql, PubDditem.class, new Object[]{});
		
	}
	
	public List<PubDditem> getFieldListByIds(List<String> itemNos){
		if (itemNos == null) {
			return null;
		}
		StringBuffer param=new StringBuffer();
		String itemNo=null;
		for (int i = 0; i < itemNos.size(); i++) {
			itemNo=itemNos.get(i);
			if (StringUtils.isBlank(itemNo)) {
				continue;
			}
			param.append(itemNo);
			if (i < itemNos.size()-1) {
				param.append(",");
			}
		}
		itemNo =param.toString();
		String sql="select * from pub_dditem_o2o where item_no in (?)";
		return o2oJdbcSession.findEntitys(sql, PubDditem.class, new Object[]{itemNo});
	}
	
}
